<template>
    <div class="ui-poptip-table">
        <table cellspacing="0" cellpadding="0" border="0">
            <colgroup>
                <col v-for="(item, index) in columns" :key="index" :width="item.width || ''">
            </colgroup>
            <thead>
                <tr>
                    <th v-for="(item, index) in columns" :key="index">
                        <div class="table-cell">{{ item.title }}</div>
                    </th>
                </tr>
            </thead>
            <tbody v-if="data.length > 0">
                <tr v-for="(row, index) in data" :key="index">
                    <td v-for="(column, ci) in columns" :key="ci">
                        <div class="table-cell">{{ row[column.key] }}</div>
                    </td>
                </tr>
            </tbody>
            <tbody v-else>
                <tr>
                    <td :colspan="columns.length">
                        <div class="table-cell" style="text-align: center; color: #999;">暂无数据</div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>
import { deepClone } from '@/libs/tools.js';
export default {
    name: 'PoptipTable',
    props: {
        columns: {
            type: Array,
            default: function() {
                return [];
            }
        },
        data: {
            type: Array,
            default: function() {
                return [];
            }
        }
    }
}
</script>

<style>
.ui-poptip-table {
    margin: 5px 0;
    max-height: 235px;
    overflow: hidden;
    overflow-y: auto;
}
.ui-poptip-table table {
    width: 100%;
    border: 1px solid #dcdee2;
    border-bottom: 0;
}
.ui-poptip-table td, .ui-poptip-table th {
    min-width: 0;
    height: 40px;
    box-sizing: border-box;
    text-align: left;
    text-overflow: ellipsis;
    vertical-align: middle;
    border-bottom: 1px solid #e8eaec;
}
.ui-poptip-table thead tr th {
    position: relative;
    padding: 8px 0;
    height: 100%;
    white-space: nowrap;
    overflow: hidden;
    background-color: #f8f8f9;
}
.ui-poptip-table .table-cell {
    padding-left: 12px;
    padding-right: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: normal;
    word-break: break-all;
    box-sizing: border-box;
}
</style>